package com.chenwenxuan.sync.ui.editor;

import java.util.List;

import com.chenwenxuan.sync.ui.AbstractAction;
import com.chenwenxuan.sync.ui.Activator;
import com.chenwenxuan.sync.ui.AppWindow;
import com.chenwenxuan.sync.ui.tree.AppNavigation;

public class DefaultEditorActivator implements Activator {
	
	private List <AbstractAction> actionList;
	
	@Override
	public void start() {
		
		for ( AbstractAction action : actionList ) {
			registerBeforeMenuDisplayHandle(action);
			registerDefaultOpenEditorAction(action);
		}
		
	}


	private void registerBeforeMenuDisplayHandle(AbstractAction action) {
		for ( String eventName : action.getNavigationEvents() ) {
			if (AppNavigation.FillNavPopMenuEvent.getName().equals(eventName)) {
				AppWindow.getAppNavigation().getMenuManager().addEventHandler(action, eventName);
			}
		}
	}
	
	private void registerDefaultOpenEditorAction(AbstractAction action) {
		if (action.isDefaultAction()) {
			AppWindow.getAppNavigation().addDefaultOpenEditorAction(action);;
		}
	}


	@Override
	public void stop() {
		
	}

	public List <AbstractAction> getActionList() {
		return actionList;
	}

	public void setActionList(List <AbstractAction> actionList) {
		this.actionList = actionList;
	}

}
